package com.edu.jsu.egoumail.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @program: egoumaill
 * @description:
 * @author: 廖俊杰
 * @date: 2021/9/23 15:44
 **/
public class ListValueConstrainValidator implements ConstraintValidator<ListValue,Integer> {


    private Set<Integer> set = new HashSet<>();

    @Override
    public void initialize(ListValue constraintAnnotation) {
       int [] values = constraintAnnotation.values();
       for (int value : values){
           set.add(value);
       }
    }

    /**
     *
     * @param value 需要校验的值
     * @param context
     * @return
     */
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {


        return set.contains(value);
    }
}
